﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PrinteMaster
{
    public partial class 增加会员窗口Ex : Form
    {
        public 增加会员窗口Ex()
        {
            InitializeComponent();
        }

        private void textBoxQQ号_Enter(object sender, EventArgs e)
        {

        }

        private void textBoxQQ号_KeyPress(object sender, KeyPressEventArgs e)
        {

        }

        private void textBox1_Leave(object sender, EventArgs e)
        {

        }

        private void textBox姓名_Enter(object sender, EventArgs e)
        {

        }

        private void textBox姓名_Leave(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (textBox短手机号.Text != "" && textBox短手机号.Text.Length != 6)
            {
                MessageBox.Show("手机短号要么为空必须为6位!");
                return;
            }
            textBox短号确认.Text = textBox短手机号.Text;
            tabControl1.SelectedTab = tabPage5;
        }

        private void textBox短手机号_Enter(object sender, EventArgs e)
        {

        }

        private void textBox短手机号_KeyPress(object sender, KeyPressEventArgs e)
        {

        }

        private void textBox短手机号_Leave(object sender, EventArgs e)
        {

        }

        private void textBox手机号_Enter(object sender, EventArgs e)
        {

        }

        private void textBox手机号_KeyPress(object sender, KeyPressEventArgs e)
        {

        }

        private void textBox手机号_Leave(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            //验证有效性
            if (textBoxQQ号.Text.Length == 0 || textBoxQQ号.Text.Length > 20)
            {
                MessageBox.Show("qq号不能为空!且长度必须小于21");
                return;
            }
            tabControl1.SelectedTab = tabPage2;
            textBoxQQ确认.Text = textBoxQQ号.Text;
        }

        private void textBoxQQ号_KeyPress_1(object sender, KeyPressEventArgs e)
        {
            Function.inputInt(sender, e);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox姓名.Text.Length == 0 || textBox姓名.Text.Length > 10)
            {
                MessageBox.Show("姓名不能为空!且长度必须小于6个字!");
                return;
            }
            tabControl1.SelectedTab = tabPage3;
            textBox姓名确认.Text = textBox姓名.Text;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox手机号.Text.Length > 11)
            {
                MessageBox.Show("手机长号必须小于11位!");
                return;
            }
            else if (textBox手机号.Text.Length != 11)
            {
                if(MessageBox.Show("侦测到你手机号不为11位，是外国手机号么？","",MessageBoxButtons.OKCancel)!=DialogResult.OK)
                    return;
            }
            tabControl1.SelectedTab = tabPage4;
            textBox手机长号确认.Text = textBox手机号.Text;
        }

        private void textBoxQQ确认_MouseUp(object sender, MouseEventArgs e)
        {
            tabControl1.SelectedTab = tabPage1;
        }

        private void textBox姓名确认_MouseUp(object sender, MouseEventArgs e)
        {
            tabControl1.SelectedTab = tabPage2;
        }

        private void textBox手机长号确认_MouseUp(object sender, MouseEventArgs e)
        {
            tabControl1.SelectedTab = tabPage3;
        }

        private void textBox短号确认_MouseUp(object sender, MouseEventArgs e)
        {
            tabControl1.SelectedTab = tabPage4;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            //如果没退出，填充结构体。
            DataBase.UserInfo info = new DataBase.UserInfo();
            info.id = textBoxQQ号.Text;
            //info.money = Convert.ToDouble(textBox首充金额.Text);
            info.name = textBox姓名.Text;
            info.phoneNumber = textBox手机号.Text;
            info.pw = textBoxQQ号.Text;
            info.shortPhoneNumber = textBox短手机号.Text;
            DataBase.Error error = DataBase.getInstance().addUser(info);
            if (error == DataBase.Error.ok)
            {
                MessageBox.Show("注册会员成功!提示语句已复制到剪贴板，你也可以在下方寻找到它.");
                var hint = string.Format("您好，我是懒人自助打印客服第{0}号\r\n您申请的会员注册已通过审核!\r\n注册账号:{1}\r\n注册姓名:{2}\r\n手机号:{3}\r\n 默认情况下，密码与账号相同。请您尽快修改密码并进行充值，祝您生活愉快.",
                    客服窗口.m_ManagerInfo.id, textBoxQQ号.Text, textBox姓名.Text, textBox手机号.Text);
                textBox提示语句.Text = hint;
                Clipboard.SetDataObject(textBox提示语句.Text);
                tabControl1.SelectedTab = tabPage6;
                //this.Close();
                //return;
            }
            else if (error == DataBase.Error.已有该账号)
            {
                MessageBox.Show("QQ号或手机号重复,不能注册");
            }
            else
            {
                MessageBox.Show("注册会员失败，失败原因=>" + error.ToString());
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (textBox提示语句.Text.Length != 0)
            {
                MessageBox.Show("复制语句成功，你可以在qq窗口内按下ctrl+v或鼠标右键点击复制!");
                Clipboard.SetDataObject(textBox提示语句.Text);
            }
            else
            {
                MessageBox.Show("没有可复制的语句!");
            }
        }

        private void textBox姓名_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void textBox手机号_KeyPress_1(object sender, KeyPressEventArgs e)
        {
            Function.inputInt(sender, e);
        }

        private void textBox短手机号_KeyPress_1(object sender, KeyPressEventArgs e)
        {
            Function.inputInt(sender, e);
        }

        private void textBoxQQ确认_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }

        private void textBox姓名确认_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }

        private void textBox手机长号确认_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }

        private void textBox短号确认_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }
    }
}
